@extends('layouts.back_stage')
@section('content')
    <style>
        .el-table-add-row {margin-top: 10px;width: 100%;height: 34px;border: 1px dashed #c1c1cd;border-radius: 3px;cursor: pointer;justify-content: center;display: flex;line-height: 34px;}
        [v-cloak] {display: none;}
        .back{background:#fff;margin:20px;padding:10px}
        .type_x{margin:20px 0 0 20px;}
        .ingred_sel{width:200px;margin-right:10px}
        .add_s{margin:20px 0 0 20px}
        .addsert{font-weight:500;margin:20px 0 0 30px}
        .disscount{margin:20px 0 40px 20px;}
        .input_disscount{width:200px;margin-right:40px}
        .tab_show{margin:10px 0 20px 20px}
        .form_t{margin-left:40px}
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .span{display:inline-block;width:200px;height:29px;border:1px solid #E5E7F0;line-height:29px;color:#ccc;background:#f5f7fa;border-radius: 4px;padding: 0 10px;}
        .el-upload__input{opacity:0}
        .rest{margin:10px 0 0 40px}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 style="float:left;">测试</h3></div>
        <!-- 主体-->
        <div class="page-body">
            <div class="row app" id="app" v-cloak>
                <el-form :model="ruleForm"  class="demo-ruleForm">
                    <div class="header"><h3>修改基本信息</h3></div>
                    <div class="back">
                        <div class="type_x">
                            <label>客户类型：</label>
                            <el-select placeholder="请选择客户类型" size="small" v-model="ruleForm.type" class="ingred_sel">
                                <el-option :value="1" label="分公司">分公司</el-option>
                                <el-option :value="2" label="代理商">代理商</el-option>
                                <el-option :value="3" label="客户">客户</el-option>
                            </el-select>
                            <label>客户名称：</label>
                            <el-input  class="ingred_sel" v-model="ruleForm.name"  maxlength="10"   size="small" placeholder="请输入客户名称"></el-input>
                            <label>手机号码：</label>
                            <el-input  class="ingred_sel" maxlength="11" v-model="ruleForm.tel" size="small" placeholder="请输入手机号"></el-input>
                        </div>
                        <div class="type_x">
                            <label>所属机构：</label>
                            <span class="span" style="width:500px;" disabled>@{{pidName}}</span>
                        </div>
                        <div class="add_s">
                            <label>省 市 区：</label>
                            <el-cascader style="width:500px;margin-left: 5px;" :options="options"  class='caser'  :placeholder="pleader" size="small" change-on-select v-model="ruleForm.area"></el-cascader>
                        </div>
                        <div class="addsert">
                            <label>地 址:</label>
                            <el-input style="width:500px;margin-left: 23px;" class="input_add on" maxlength="30" v-model="ruleForm.address" size="small" placeholder="请输入地址"></el-input>
                        </div>
                        <div class="disscount">
                            <label>默认拿货折扣：</label>
                            <el-input  class="input_disscount on" v-model="ruleForm.discount_default" size="small" maxlength="5" placeholder="请输入0-1之间的数"></el-input>
                        </div>
                    </div>
                    <div class="font_a"><h3>政策信息</h3></div>
                    <div class="back">
                        <el-tabs type="border-card" v-model="activeName" :before-leave="tabsBefore" @tab-click="tabsform">
                            <el-tab-pane v-for="itme in opt" :label="itme.name" :key="itme.textId" :name=`${itme.textId}`>
                                <div class="tab_show" >
                                    <label>折扣：</label>
                                    <el-input class="input_disscount on" maxlength="4" v-model="ruleForm.policy_discount" size="small" placeholder="请输入0-1之间的数"></el-input>
                                </div>
                                <div class="sales">
                                    <h4>退货率：</h4>
                                    <el-form :inline="true" class="demo-form-inline form_t">
                                        <div>
                                            <el-form-item label="第一季度：">
                                                <el-input v-model="ruleForm.first_rate" maxlength="5" size="small" placeholder="请输入0-100的数"></el-input>
                                            </el-form-item>
                                            <el-form-item label="退货期限： 选择日期">
                                                <el-date-picker v-model="ruleForm.first_daterange" type="daterange"  size="small" value-format="yyyy-MM-dd " range-separator="至"  start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
                                            </el-form-item>
                                        </div>
                                        <div>
                                            <el-form-item label="第二季度：">
                                                <el-input v-model="ruleForm.second_rate" size="small"  maxlength="5"  placeholder="请输入0-100的数"></el-input>
                                            </el-form-item>
                                            <el-form-item label="退货期限： 选择日期">
                                                <el-date-picker v-model="ruleForm.second_daterange" type="daterange" value-format="yyyy-MM-dd "  size="small"  range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
                                            </el-form-item>
                                        </div>
                                        <div>
                                            <el-form-item label="第三季度：">
                                                <el-input v-model="ruleForm.third_rate" size="small" maxlength="5" placeholder="请输入0-100的数"></el-input>
                                            </el-form-item>
                                            <el-form-item label="退货期限： 选择日期">
                                                <el-date-picker v-model="ruleForm.third_daterange" type="daterange"  size="small"  value-format="yyyy-MM-dd " range-separator="至"   start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                                            </el-form-item>
                                        </div>
                                        <div>
                                            <el-form-item label="第四季度：">
                                                <el-input v-model="ruleForm.fourth_rate" size="small" maxlength="5" placeholder="请输入0-100的数"></el-input>
                                            </el-form-item>
                                            <el-form-item label="退货期限： 选择日期">
                                                <el-date-picker v-model="ruleForm.fourth_daterange" type="daterange"  size="small"  value-format="yyyy-MM-dd " range-separator="至"   start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                                            </el-form-item>
                                        </div>
                                        <div>
                                            <el-form-item label="全年总数：">
                                                <el-input v-model="ruleForm.year_rate" size="small" maxlength="5" placeholder="请输入0-100的数"></el-input>
                                            </el-form-item>
                                            <el-form-item label="退货期限： 选择日期">
                                                <el-date-picker v-model="ruleForm.year_daterange" type="daterange" size="small"  value-format="yyyy-MM-dd" range-separator="至"   start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                                            </el-form-item>
                                        </div>
                                    </el-form>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </div>
                    <div class="font_a"><h3>合同管理</h3></div>
                    <div class="back">
                        <p>协议附件</p>
                        <el-upload action="/clients/uploadagreement" list-type="picture-card" name="agreement" :file-list="fileList" :on-preview="handlePictureCardPreview" :on-success="successFile" :before-upload="beforeAvatarUpload" :on-remove="handleRemove"><i class="el-icon-plus"></i></el-upload>
                        <el-dialog :visible.sync="dialogVisible"><img width="100%" :src="dialogImageUrl" alt=""></el-dialog>
                        <span style="color:#ccc">上传图片必须是JPG/PNG 格式  且不大于2M</span>
                        <input  type="hidden" name="agreement"/>
                    </div>
                    <el-form-item>
                        <el-button type="primary" class="rest" size="small" @click="formSubmit">修改提交</el-button>
                        <el-button type="primary" size="small" @click="resetForm">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
    </div>
    <script>
        //主要内容
        new Vue({
            el: "#app",
            data() {
                return {
                    ruleForm: {
                        type: '',//客户类型
                        name: '',//客户名称
                        tel: '',//手机号码
                        pid: '',
                        area: [], //省 市 区
                        area_bh: '',
                        address: '', //地 址
                        discount_default: '', //拿货折扣
                        agreement: '',

                        policy_discount: '', //折扣
                        first_rate: '', //第一季度退货率
                        first_daterange: '', //第一季度时间
                        second_rate: '', //第二季度退货率
                        second_daterange: '', //第二季度时间
                        third_rate: '', //第三季度退货率
                        third_daterange: '', //第三季度时间
                        fourth_rate: '', //第四季度退货率
                        fourth_daterange: '', //第四季度时间
                        year_rate: '', //全年退货率
                        year_daterange: '', //全年时间
                    },
                    options: [],//省市区
                    pidName: '',//所属机构
                    companyList: [],//机构下拉


                    policies: {},
                    area_bh1: '',


                    activeName: '1',//tab切换tab的ID
                    opt: [],//tab切换发货类型
                    tabId: '', //tab的ID



                    agreement: '',//图片上传
                    dialogVisible: false,//图片上传
                    dialogImageUrl: '',//图片上传
                    fileList: [],//点击修改显示上传默认图片
                    wq: {
                        name: 'a',
                        type: 'b'
                    },

                    text: '',
                    first: '',
                    second: '',
                    third: '',
                    fourth: '',
                    year: '',
                    first1: [],
                    second1: [],
                    third1: [],
                    fourth1: [],
                    year1: [],
                    updateId: '',//页面加载是页面的id
                    pleader: '',//省市区默认值



                    temporary:{}//暂存数据


                }
            },
            created(){
                this.updateId=window.location.href.split('=')[1]
            },
            mounted(){
                this.handleChange(); //省市区
                this.getCompanyList(); //所属机构
                this.request(); //tab切换
                this.demand();
            },
            methods: {
                //省市区三级联动
                handleChange(value) {
                    const that=this;
                    $.ajax({
                        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                        type:'get',
                        url:'/clients/address'
                    }).then(function(res){
                        const options = [];
                        for (let item in res) {
                            let province = {
                                value: res[item].value,
                                label: res[item].label,
                                children: []
                            };
                            for (let city in res[item].children) {
                                let counties=[];
                                for (let county in res[item].children[city].children) {
                                    let cityno=res[item].children[city].children[county];
                                    counties.push({value:cityno.value,label:cityno.label});
                                }
                                province.children.push({
                                    value: res[item].children[city].value,
                                    label: res[item].children[city].label,
                                    children:counties
                                });
                            }
                            options.push(province)
                        }
                        that.$data.options=options;
                    })
                },
                //所属机构
                getCompanyList(){
                    let that=this
                    let list=[]
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content'),
                            'contentType':'application/json'
                        },
                        url: '/clients/getall',
                        type: 'get',
                        dataType: 'json',
                        success:res=>{
                            if(res.result.success){
                                for(let value of res.content[1]){
                                    value['value'] = value.id
                                    value['label'] = value.company_name
                                    let child_data = res.content[1].filter((n) => n.pid == value.id && n.id != value.id)
                                    if(child_data.length > 0){
                                        value['children'] = child_data
                                    }
                                }
                                // console.log(res.content[1].filter((n) => n.id == res.content[0]))
                                this.companyList = res.content[1].filter((n) => n.id == res.content[0])
                                // this.companyList = res.content[1]
                                // console.log(this.companyList)
                            }else{
                                this.$notify.error({
                                    title: '错误',
                                    message: res.result.errorMsg
                                })
                            }
                        }
                    })
                },
                //tab切换遍历
                request(){
                    let that=this
                    let textId=''
                    let list=[]
                    $.ajax({
                        type:'get',
                        url:'/deliver/index'
                    }).then(function(res){
                        for(var x in res.content){
                            list.push({
                                textId:res.content[x].id,
                                name:res.content[x].name
                            })
                        }
                        that.opt=list;
                    })
                },
                //点击tabs
                tabsform(tab, event){
                    this.activeName=tab.name//当前点击tab的id
                    console.log(tab.name)
//                    console.log(jQuery.isEmptyObject())
                    let obj=this.temporary;
                    for(value in obj){
                        if(value==tab.name){
                            obj[value]
                        }
                    }
                },
                //tab切换之前判断
                tabsBefore(){
                    if( this.ruleForm.first_rate=='' && this.ruleForm.first_daterange!=''){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第一季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.first_rate!=''  &&  this.ruleForm.first_daterange=='' ){
                       this.$notify.error({
                           title: '提示',
                           message: '请填选完整第一季度退货率与时间',
                       });
                       return  false;
                    }
                    if( this.ruleForm.second_rate=='' && this.ruleForm.second_daterange!='' ){
                       this.$notify.error({
                           title: '提示',
                           message: '请填选完整第二季度退货率与时间',
                       });
                       return  false;
                    }
                    if( this.ruleForm.second_rate!='' && this.ruleForm.second_daterange=='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第二季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.third_rate=='' &&  this.ruleForm.third_daterange!='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第三季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.third_rate!='' &&  this.ruleForm.third_daterange=='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第三季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.fourth_rate=='' &&   this.ruleForm.fourth_daterange!='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第四季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.fourth_rate!='' &&   this.ruleForm.fourth_daterange=='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整第四季度退货率与时间',
                        });
                        return  false;
                    }
                    if( this.ruleForm.year_rate==''  && this.ruleForm.year_daterange!='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整全年退货率与时间',
                        });
                        return   false;
                    }
                    if( this.ruleForm.year_rate!=''  && this.ruleForm.year_daterange=='' ){
                        this.$notify.error({
                            title: '提示',
                            message: '请填选完整全年退货率与时间',
                        });
                        return   false;
                    }
                    //不全为空时暂存
                    if(this.ruleForm.policy_discount=='' && this.ruleForm.first_rate=='' && this.ruleForm.first_daterange=='' && this.ruleForm.second_rate=='' && this.ruleForm.second_daterange=='' && this.ruleForm.third_rate=='' &&  this.ruleForm.third_daterange=='' && this.ruleForm.fourth_rate=='' &&   this.ruleForm.fourth_daterange=='' && this.ruleForm.year_rate==''  && this.ruleForm.year_daterange=='') {

                    }else{
                        //暂存之前判断有没有这个id的数据，有就删除替换，没有就存起来

                        //暂存
                        let json={};
                        json['policy_discount']=this.ruleForm.policy_discount;
                        json['spring_rate']=this.ruleForm.first_rate;
                        json['spring_end']=this.ruleForm.first_daterange;
                        json['summer_rate']=this.ruleForm.second_rate;
                        json['summer_end']=this.ruleForm.second_daterange;
                        json['fall_rate']=this.ruleForm.third_rate;
                        json['fall_end']=this.ruleForm.third_daterange;
                        json['winter_rate']=this.ruleForm.fourth_rate;
                        json['winter_end']=this.ruleForm.fourth_daterange;
                        json['year_rate']=this.ruleForm.year_rate;
                        json['year_end']=this.ruleForm.year_daterange;
                        this.temporary[this.activeName]=json;

                        //暂存完清空
                        this.ruleForm.policy_discount='';
                        this.ruleForm.first_rate='';
                        this.ruleForm.first_daterange='';
                        this.ruleForm.second_rate='';
                        this.ruleForm.second_daterange='';
                        this.ruleForm.third_rate='';
                        this.ruleForm.third_daterange='';
                        this.ruleForm.fourth_rate='';
                        this.ruleForm.fourth_daterange='';
                        this.ruleForm.year_rate='';
                        this.ruleForm.year_daterange='';

                        console.log(this.temporary)
                    }
                },

                //已上传的文件时的钩子
                handlePictureCardPreview(file) {
                    this.dialogImageUrl = file.url;
                    this.dialogVisible = true;
                },
                //上传成功时的文件时的钩子
                successFile(response, file, fileList){
                    let that=this
                    for(var e in fileList){
                        this.ruleForm.agreement=fileList[e].response.content
                        this.agreement=fileList[e].response.content
                    }
                },
                //上传之前判断
                beforeAvatarUpload(file) {
                    const isJPG = file.type === 'image/jpeg';
                    const isPNG = file.type === 'image/png';
                    const isLt2M = file.size / 1024 / 1024 < 2;
                    if (!isJPG &&  !isPNG ) {
                        this.$notify({
                            title: '警告',
                            message: '上传图片必须是JPG/PNG/BMP 格式!',
                            type: 'warning'
                        });
                        return false;
                    }
                    if (!isLt2M) {
                        this.$notify({
                            title: '警告',
                            message: '上传头像图片大小不能超过 2MB!',
                            type: 'warning'
                        });
                        return false;
                    }
                    return (isJPG || isPNG )&& isLt2M;
                },
                //移除文件时的钩子
                handleRemove(file, fileList) {

                },
                //重置
                resetForm(){
                    this.ruleForm.type=''
                    this.ruleForm.pid=''
                    this.ruleForm.name=''
                    this.ruleForm.tel=''
                    this.ruleForm.address=''
                    this.ruleForm.discount_default=''
                    this.ruleForm.type_form=''
                    this.ruleForm.policy_discount=''
                    this.ruleForm.first_rate=''
                    this.ruleForm.second_rate=''
                    this.ruleForm.third_rate=''
                    this.ruleForm.fourth_rate=''
                    this.ruleForm.year_rate=''
                    this.ruleForm.first_daterange=''
                    this.ruleForm.second_daterange=''
                    this.ruleForm.third_daterange=''
                    this.ruleForm.fourth_daterange=''
                    this.ruleForm.year_daterange=''
                    this.ruleForm.policy_type=''
                    this.ruleForm.area_bh=''
                    this.ruleForm.area=[]
                    this.$notify.success({
                        title: '成功',
                        message: '重置清空成功',
                        type: 'success'
                    });
                },
                //提交
                formSubmit(){
                    let that=this
                    if(this.ruleForm.type==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择客户类型',
                        });
                        return false;
                    }
                    if(this.ruleForm.name==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请输入客户名',
                        });
                        return false;
                    }
                    if(this.ruleForm.tel==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请输入手机号码',
                        });
                        return false;
                    }
                    var moder=/^1[3-9]\d{9}$/
                    if(!moder.test(this.ruleForm.tel)){
                        this.$notify.error({
                            title: '提示',
                            message: '手机号码格式有问题，请输入正确的号码',
                        });
                        return false;
                    }
                    if(this.ruleForm.area==undefined){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择省市区',
                        });
                        return false;
                    }
                    //   this.ruleForm.area_bh=this.ruleForm.area[this.ruleForm.area.length-1]
                    if(this.ruleForm.address==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请输入详细地址',
                        });
                        return false;
                    }
                    if(this.ruleForm.discount_default==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请输入默认折扣',
                        });
                        return false;
                    }
                    var list=/^(0\.\d{1,2}|1(\.0{1,2})?)$/;
                    if(!list.test(this.ruleForm.discount_default)){
                        this.$notify.error({
                            title: '提示',
                            message: '请输入0-1之间的两位数折扣',
                        });
                        return false;
                    }

                    // console.log(3333,that.ruleForm.second_rate)
                    // console.log(3333,that.ruleForm.second_daterange)
                    if(that.ruleForm.policy_discount!=''){
                        var rest=/^(0\.\d{1,2}|1(\.0{1,2})?)$/;
                        if(!rest.test(that.ruleForm.policy_discount)){
                            that.$notify.error({
                                title: '提示',
                                message: '政策信息折扣有误，请输入0-100的数字',
                            });
                            return false;
                        }
                    }
                    for(var i in that.policies){
                        console.log(1212,that.policies[i])
                        if(that.policies[i].type==that.tabId){
                            if(that.policies[i].policy_discount!=''){
                                var rest=/^(0\.\d{1,2}|1(\.0{1,2})?)$/;
                                if(!rest.test(that.policies[i].policy_discount)){
                                    that.$notify.error({
                                        title: '提示',
                                        message: '政策信息折扣有误，请输入0-100的数字',
                                    });
                                    return false;
                                }
                            }
                            if(that.policies[i].first_rate==null) {
                                if(that.policies[i].first_daterange!=null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第一季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].first_rate!=null) {
                                if(that.policies[i].first_daterange==null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第一季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].first_rate=='') {
                                if(that.policies[i].first_daterange!=''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第一季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].first_rate!='') {
                                if(that.policies[i].first_daterange==''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第一季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].second_rate==null) {
                                if(that.policies[i].second_daterange!=null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第二季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].second_rate!=null) {
                                if(that.policies[i].second_daterange==null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第二季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].second_rate=='') {
                                if(that.policies[i].second_daterange!=''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第二季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].second_rate!='') {
                                if(that.policies[i].second_daterange==''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第二季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].third_rate==null) {
                                if(that.policies[i].third_daterange!=null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第三季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].third_rate!=null) {
                                if(that.policies[i].third_daterange==null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第三季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].third_rate=='') {
                                if(that.policies[i].third_daterange!=''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第三季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].third_rate!='') {
                                if(that.policies[i].third_daterange==''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第三季度填写有误',
                                    });
                                    return false
                                }
                            }

                            if(that.policies[i].fourth_rate==null) {
                                if(that.policies[i].fourth_daterange!=null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第四季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].fourth_rate!=null) {
                                if(that.policies[i].fourth_daterange==null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第四季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].fourth_rate=='') {
                                if(that.policies[i].fourth_daterange!=''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第四季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].fourth_rate!='') {
                                if(that.policies[i].fourth_daterange==''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息第四季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].year_rate==null) {
                                if(that.policies[i].year_daterange!=null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息全年季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].year_rate!=null) {
                                if(that.policies[i].year_daterange==null){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息全年季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].year_rate=='') {
                                if(that.policies[i].year_daterange!=''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息全年季度填写有误',
                                    });
                                    return false
                                }
                            }
                            if(that.policies[i].year_rate!='') {
                                if(that.policies[i].year_daterange==''){
                                    this.$notify.error({
                                        title: '提示',
                                        message: '政策信息全年季度填写有误',
                                    });
                                    return false
                                }
                            }
                        }


                    }

                    //  console.log(this.policies)
                    if(that.ruleForm.area!=''){
                        that.ruleForm.area_bh=that.ruleForm.area[that.ruleForm.area.length-1]
                        $.ajax({
                            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                            type:"put",
                            url:`/clients/update/${this.updateId}`,
                            data:{
                                name:this.ruleForm.name,
                                type:this.ruleForm.type,
                                tel:this.ruleForm.tel,
                                pid:this.ruleForm.pid,
                                address:this.ruleForm.address,
                                discount_default:this.ruleForm.discount_default,
                                area_bh:this.ruleForm.area_bh,
                                agreement:this.ruleForm.agreement,
                                policies : this.policies
                            },
                            success: function (res) {
                                if(res.result.success==true){
                                    window.location.href = "/clients/index";
                                    that.$notify.success({
                                        title: '提示',
                                        message: '创建提交成功',
                                    });
                                }else{
                                    that.$notify.error({
                                        title: '错误',
                                        message: res.result.errorMsg
                                    });
                                }
                            }
                        })
                    }else{
                        that.ruleForm.area_bh=that.area_bh1
                        $.ajax({
                            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                            type:"put",
                            url:`/clients/update/${this.updateId}`,
                            data:{
                                name:this.ruleForm.name,
                                type:this.ruleForm.type,
                                tel:this.ruleForm.tel,
                                pid:this.ruleForm.pid,
                                address:this.ruleForm.address,
                                discount_default:this.ruleForm.discount_default,
                                area_bh:this.ruleForm.area_bh,
                                agreement:this.ruleForm.agreement,
                                policies : this.policies
                            },
                            success: function (res) {
                                if(res.result.success==true){
                                    //  window.location.href = "/clients/index";
                                    that.$notify.success({
                                        title: '提示',
                                        message: '修改提交成功',
                                    });
                                }else{
                                    that.$notify.error({
                                        title: '错误',
                                        message: res.result.errorMsg
                                    });
                                }
                            }
                        })
                    }
                },
                demand(){
                    let  that=this
                    let opt=[]
                    let num =[]
                    let sprin=[]
                    let second=[]
                    let third=[]
                    let fourth=[]
                    let year=[]
                    $.ajax({
                        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
                        type:'get',
                        url:`/clients/edit/${this.updateId}`,
                        dataType:'json',
                        success:function(res){
                            console.log(res)
                            if(res.content.files!=''){
                                for(var e in res.content.files){
                                    that.fileList.push({
                                        url:res.content.files[e]

                                    })
                                }
                            }
                            //   for(var e in res.content.parents){

                            //       that.pidName=res.content.parents[e].company_name
                            //  }
                            that.pidName=res.content.parent.company_name
                            that.ruleForm.agreement=res.content.agreement,
                                that.id=res.content.id,
                                that.ruleForm.pid=res.content.parent.name,
                                that.area_bh1=res.content.area_bh,
                                that.ruleForm.pidId=res.content.parent.id,
                                that.ruleForm.type=res.content.type,
                                that.ruleForm.name=res.content.name,
                                that.pleader=res.content.province+'/'+res.content.city+'/'+res.content.district,
                                that.ruleForm.address=res.content.address,
                                that.ruleForm.discount_default=res.content.discount_default,
                                that.ruleForm.tel=res.content.tel,
                                num=res.content.policies
                            let text={}
                            for(let value of num){
                                let list={}
                                let aa={}
                                console.log(value)
                                aa={
                                    // content.policies[0].spring_rate==null?null:Number(a.content.policies[0].spring_rate)*100;
                                    type:value.policy_type,
                                    policy_discount : value.policy_discount,
                                    first_rate: value.spring_rate==null?null:Math.floor(Number(value.spring_rate)*100),
                                    second_rate: value.summer_rate==null?null:Math.floor(Number(value.summer_rate)*100) ,
                                    third_rate:  value.fall_rate==null?null:Math.floor(Number(value.fall_rate)*100),
                                    fourth_rate:value.winter_rate==null?null:Math.floor(Number(value.winter_rate)*100),
                                    year_rate:value.year_rate==null?null:Math.floor(Number(value.year_rate)*100),
                                    first_daterange:value.spring_start==null ? null :(value.spring_start+","+value.spring_end).split(','),
                                    second_daterange:value.summer_start==null ? null :(value.summer_start+","+value.summer_end).split(','),
                                    third_daterange: value.fall_start==null ? null :(value.fall_start+","+value.fall_end).split(','),
                                    fourth_daterange:value.winter_start==null ?  null :(value.winter_start+","+value.winter_end).split(','),
                                    year_daterange:value.year_end==null ? null :(value.year_end+","+value.year_end).split(','),
                                }
                                for(z in aa){
                                    list[z] = aa[z];

                                }
                                text[value.policy_type]=list;

                            }
                            console.log(text)
                            that.policies=text
                        }
                    })
                },


            }
        });
    </script>
@endsection